Skip to main content
Version: 0.4.0

getMultiRuntime

This method executes a function several times and calculates its execution time several times and puts it in an array.

Params

getMultiRuntime(inputFunction,options = { ignoreFirstTime: false, runtimeCount: 5 }) ;
  • inputFunction → The function we want to calculate its execution times
  • ignoreFirstTime → In this method, you can set this key to true and the first execution is not considered.
javascript tips

The execution time of a function in the first time is completely different from the subsequent times, because JavaScript performs optimizations on the execution of that function.

  • runtimeCount → The number of times you want this function to be executed and its time taken

Returns

{
runtimeCount: 5,
runtimes: [ 0.04217, 0.00062, 0.00033, 0.00033, 0.00067 ]
}
  • Object.runtimeCount → The number of times the function was executed
  • Object.runtimes → The execution time of this function respectively

Usage

const testFunction = ()=>{
let a = 2345345436;
let b = 45364536457;
let c = a * b;
c = c**2
}

momentMachine.getMultiRuntime(testFunction);
/*{
runtimeCount: 5,
runtimes: [ 0.04217, 0.00062, 0.00033, 0.00033, 0.00067 ]
}*/

momentMachine.getMultiRuntime(testFunction,{runtimeCount : 10});
/*{
runtimeCount: 10,
runtimes: [
0.017, 0.00079,
0.00046, 0.00037,
0.00079, 0.00037,
0.00038, 0.00042,
0.00058, 0.00142
]
}*/

momentMachine.getMultiRuntime(testFunction,{ ignoreFirstTime: true });
/*{
runtimeCount: 5,
runtimes: [ 0.00062, 0.00033, 0.00033, 0.00071, 0.00033 ]
}*/